package m3;

import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

/**
 * @Author wy
 * @Date 2021/3/2 14:11
 * @Version 1.0
 */
public class Producer {
    public static void main(String[] args) throws Exception {
        //连接
        ConnectionFactory f = new ConnectionFactory();
        f.setHost("192.168.64.140");
        f.setUsername("admin");
        f.setPassword("admin");
        Channel c = f.newConnection().createChannel();

        //定义交换机
        //c.exchangeDeclare("logs","fanout");
        c.exchangeDeclare("logs", BuiltinExchangeType.FANOUT);

        //向交换机发送消息
        while(true){
            System.out.println("输入消息:  ");
            String s = new Scanner(System.in).nextLine();
            //第二个参数 对于fanout交换机无效
            c.basicPublish("logs","",null,s.getBytes());
        }

    }

}
